package com.rs.game.player.actions;

import com.rs.Settings;
import com.rs.game.Animation;
import com.rs.game.Graphics;
import com.rs.game.WorldTile;
import com.rs.game.player.Player;
import com.rs.game.player.content.Magic;

public class HomeTeleport extends Action {

	private final int HOME_ANIMATION = 16385, HOME_GRAPHIC = 3017;
	public static final WorldTile LUMBRIDGE_LODE_STONE = new WorldTile(3233, 3221, 0),
			BURTHORPE_LODE_STONE = new WorldTile(2899, 3544, 0),
			LUNAR_ISLE_LODE_STONE = new WorldTile(2085, 3914, 0),
			BANDIT_CAMP_LODE_STONE = new WorldTile(3214, 2954, 0),
			TAVERLY_LODE_STONE = new WorldTile(2878, 3442, 0),
			ALKARID_LODE_STONE = new WorldTile(3297, 3184, 0),
			VARROCK_LODE_STONE = new WorldTile(3214, 3376, 0),
			EDGEVILLE_LODE_STONE = new WorldTile(3067, 3505, 0),
			FALADOR_LODE_STONE = new WorldTile(2967, 3403, 0),
			PORT_SARIM_LODE_STONE = new WorldTile(3011, 3215, 0),
			DRAYNOR_VILLAGE_LODE_STONE = new WorldTile(3105, 3298, 0),
			ARDOUGNE_LODE_STONE = new WorldTile(2634, 3348, 0),
			CATHERBAY_LODE_STONE = new WorldTile(2831, 3451, 0),
			YANILLE_LODE_STONE = new WorldTile(2529, 3094, 0),
			SEERS_VILLAGE_LODE_STONE = new WorldTile(2689, 3482, 0),
			REAL_HOME_TELEPORT = Settings.RESPAWN_PLAYER_LOCATION;

	private int currentTime;
	private WorldTile tile;

	public HomeTeleport(WorldTile tile) {
		this.tile = tile;
	}

	@Override
	public boolean start(final Player player) {
		if (!player.getControlerManager().processMagicTeleport(tile))
			return false;
		return process(player);
	}

	@Override
	public int processWithDelay(Player player) {
		if (currentTime++ == 0) {
			if (player.Demon == true && player.Ass == false && player.Gnome == false && player.SuperJump == false && player.Pony == false) {
				player.setNextAnimation(new Animation(17108));
				player.setNextGraphics(new Graphics(3224));
				player.setNextGraphics(new Graphics(3225));
			}
			if (player.Demon == false && player.Ass == false && player.Gnome == false && player.SuperJump == false && player.Pony == true) {
				player.setNextAnimation(new Animation(17106));
				player.setNextGraphics(new Graphics(3223));
			}
			if (player.Demon == false && player.Ass == true && player.Gnome == false && player.SuperJump == false && player.Pony == false) {
				player.setNextAnimation(new Animation(17074));
				player.setNextGraphics(new Graphics(3215));
			}
			if (player.Demon == false && player.Ass == false && player.Gnome == true && player.SuperJump == false && player.Pony == false) {
				player.setNextAnimation(new Animation(17191));
				player.setNextGraphics(new Graphics(3254));
			}
			if (player.Demon == false && player.Ass == false && player.Gnome == false && player.SuperJump == true && player.Pony == false) {
				player.setNextAnimation(new Animation(17106));
				player.setNextGraphics(new Graphics(3223));
			}
			if (player.Demon == false && player.Ass == false && player.Gnome == false && player.SuperJump == false && player.Pony == false) {
				player.setNextAnimation(new Animation(HOME_ANIMATION));
				player.setNextGraphics(new Graphics(HOME_GRAPHIC));
			}
		} else if (currentTime == 18) {
			player.setNextWorldTile(tile.transform(0, 1, 0));
			player.getControlerManager().magicTeleported(Magic.MAGIC_TELEPORT);
			if (player.getControlerManager().getControler() == null)
				Magic.teleControlersCheck(player, tile);
			player.setNextFaceWorldTile(new WorldTile(tile.getX(), tile.getY(), tile.getPlane()));
			player.setDirection(6);
		} else if (currentTime == 19) {
			player.setNextGraphics(new Graphics(HOME_GRAPHIC + 1));
			player.setNextAnimation(new Animation(HOME_ANIMATION + 1));
		} else if (currentTime == 24) {
			player.setNextWorldTile(tile);
			player.setNextAnimation(new Animation(16393));
		} else if (currentTime == 25)
			return -1;
		return 0;
	}

	@Override
	public boolean process(Player player) {
		return true;
	}

	@Override
	public void stop(Player player) {
		player.setNextAnimation(new Animation(-1));
		player.setNextGraphics(new Graphics(-1));
	}

}